//游戏开始的时候90%生成一个2，10%生成一个4，一共生成3个。
//当前所有的节点数组
let imgs = document.querySelectorAll('#con div img');

console.log(imgs);
start();

//生成2或者4方法,传进来的是下标
function shengcheng2huozhe4(randomPosition) {
    if(Math.random() <= 0.9){
        imgs[randomPosition].setAttribute('value','2');
        imgs[randomPosition].src = './img/cube_' + 2 +
        '.png';
    }else{
        imgs[randomPosition].setAttribute('value','4');
        imgs[randomPosition].src = './img/cube_' + 4 +
        '.png';
    }
}

function start(){
    let randomPosition = Math.floor(Math.random() * 16);
    shengcheng2huozhe4(randomPosition);
    let randomPosition2 = Math.floor(Math.random() * 16);
    while(randomPosition2 == randomPosition){
        randomPosition2 = Math.floor(Math.random() * 16);
    }
    shengcheng2huozhe4(randomPosition2);
    let randomPosition3 = Math.floor(Math.random() * 16);
    while(randomPosition3 == randomPosition){
        randomPosition3 = Math.floor(Math.random() * 16);
    }
    shengcheng2huozhe4(randomPosition3);
}